package com.neu.service.ww;


import com.neu.dao.ww.OrderInfoDao;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class OrderInfoService {
    private OrderInfoDao orderInfoDao;
    public OrderInfoService(){
        orderInfoDao=new OrderInfoDao();
    }
    public int doInsertOrderInfo(List<Map<String,Object>> mapList){
        int row=0;
        List<List<String>> lists=new ArrayList<>();

        for (int i = 0; i < mapList.size(); i++) {
            Map<String, Object> aMapList = mapList.get(i);
            List<String> list=new ArrayList<>();
            list.add(aMapList.get("G_ID").toString());
            list.add(aMapList.get("G_NAME").toString());
            float price = (float) (Double.valueOf(aMapList.get("G_NOW").toString()) * Double.valueOf(aMapList.get("E_DIS").toString()));
            list.add(String.valueOf(price));
            list.add(aMapList.get("num").toString());
            lists.add(list);
        }
        System.out.println(lists);
        try {
            row=orderInfoDao.insertOrderInfo(lists);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return row;
    }

    //查日销售量
    public List<Map<String,Object>> doFindOrderInfoByDate(String k_name){
        List<Map<String,Object>> list=null;
        String date=LocalDate.now().toString();
        try {
            list=orderInfoDao.findOrderInfoByDate(date,k_name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    public List<Map<String,Object>> doFindOrderInfoByMonth(String month,String k_name){
        List<Map<String,Object>> list=null;
        try {
            list=orderInfoDao.findOrderInfoByMonth(month,k_name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String,Object>> doFindOrderInfoTen(){
        List<Map<String,Object>> list=null;

        try {
            list=orderInfoDao.findOrderInfoTen();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

}
